/*
 * SecondKillStateLayout.java
 * business
 *
 * Created by ChenTao on 2017/2/21.
 *
 * Copyright (c) 2017年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.widget.view;

import static com.yidiandao.business.utils.UIUtils.getString;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.yidiandao.business.R;
import com.yidiandao.business.data.bean.Goods;

/** 管理秒杀进行状态的Layout */
public class SecondKillStateLayout extends RelativeLayout {

    private ImageView mIvBgCircle;

    private TextView mTvState;

    private TextView mTvRunning;

    public SecondKillStateLayout(Context context) {
        this(context, null);
    }

    public SecondKillStateLayout(Context context, AttributeSet attrs) {
        super(context, attrs);

        View rootView = View.inflate(context, R.layout.second_kill_state_layout, this);

        mIvBgCircle = (ImageView) rootView.findViewById(R.id.iv_bg_circle);
        mTvState = (TextView) rootView.findViewById(R.id.tv_state);
        mTvRunning = (TextView) rootView.findViewById(R.id.tv_running);
    }

    /** 设置layout的状态 */
    public void setState(Goods goods) {

        int state = goods.getState();
        String time = goods.getNotice();
        int isSaleOff = goods.getIsSaleOff();

        switch (state) {
            case Goods.ACTIVE_STATE.FINISHED:
                mIvBgCircle.setVisibility(VISIBLE);
                mTvState.setVisibility(VISIBLE);
                mTvState.setText(R.string.finished);
                mTvRunning.setVisibility(GONE);
                break;
            case Goods.ACTIVE_STATE.RUNNING:
                if (isSaleOff == Goods.ACTIVE_STATE.SALE_OFF) {
                    mIvBgCircle.setVisibility(VISIBLE);
                    mTvState.setVisibility(VISIBLE);
                    mTvState.setText(getString(R.string.sale_off));
                    mTvRunning.setVisibility(GONE);
                } else {
                    mIvBgCircle.setVisibility(GONE);
                    mTvState.setVisibility(GONE);
                    mTvRunning.setVisibility(VISIBLE);
                }
                break;
            case Goods.ACTIVE_STATE.UN_START:
                mIvBgCircle.setVisibility(VISIBLE);
                mTvState.setVisibility(VISIBLE);
                mTvState.setText(time + "\n" + getString(R.string.second_kill));
                mTvRunning.setVisibility(GONE);
                break;
        }
    }
}
